import atexit
from init_project import app
from api.db import db_bp
from api.auth import auth_bp
from api.user import user_bp
from api.permission import permission_bp
from api.role import role_bp
from api.contacts import contact_bp
from api.field import field_stack_bp
from api.area import field_area_bp
from api.image import image_bp
from api.box_type import box_type_bp
from api.box_tag import box_tag_bp
from api.box import box_bp
from api.info import info_bp
from api.configuration import conf_bp
from apsechedu import scheduler
from api.lead import lead_bp
from api.wechat_mp import wechat_bp

app.register_blueprint(db_bp)
app.register_blueprint(auth_bp)
app.register_blueprint(user_bp)
app.register_blueprint(permission_bp)
app.register_blueprint(role_bp)
app.register_blueprint(contact_bp)
app.register_blueprint(field_stack_bp)
app.register_blueprint(field_area_bp)
app.register_blueprint(image_bp)
app.register_blueprint(box_tag_bp)
app.register_blueprint(box_type_bp)
app.register_blueprint(box_bp)
app.register_blueprint(info_bp)
app.register_blueprint(conf_bp)
app.register_blueprint(lead_bp)
app.register_blueprint(wechat_bp)

# 确保应用关闭时调度器也关闭
atexit.register(lambda: scheduler.shutdown())

if __name__ == '__main__':
    app.run()
